import {UserFormData, UserPageResult, UserQueryParam} from "@/types/system/user";
import {AxiosPromise} from "axios";
import request from "@/utils/request";

/**
 * 获取用户分页列表
 *
 * @param queryParams
 */
export function listUserPages(queryParams: UserQueryParam): AxiosPromise<UserPageResult> {
  return request({
    url: '/user/listByPage',
    method: 'get',
    params: queryParams,
  });
}

/**
 * 获取用户表单详情
 *
 * @param userId
 */
export function getUserDetail(userId: number): AxiosPromise<UserFormData> {
  return request({
    url: `/user/details/${userId}`,
    method: 'get',
  });
}


/**
 * 添加用户
 *
 * @param data
 */
export function addUser(data: any): AxiosPromise<number> {
  return request({
    url: '/user/add',
    method: 'post',
    data: data,
  });
}

/**
 * 修改用户
 *
 * @param id
 * @param data
 */
export function updateUser(id: string, data: UserFormData) {
  return request({
    url: '/user/updateById/' + id,
    method: 'put',
    data: data,
  });
}

/**
 * 修改用户状态
 *
 * @param id
 * @param status
 */
export function updateUserStatus(id: string, status: number) {
  return request({
    url: '/user/updateUserStatus/' + id,
    method: 'put',
    params: {status: status},
  });
}


/**
 * 修改用户密码
 *
 * @param id
 * @param password
 */
export function updateUserPassword(id: string, password: string, pastPassword: any) {
  return request({
    url: '/user/updatePasswordById/' + id,
    method: 'put',
    data: {password: password, pastPassword: pastPassword},
  });
}


/**
 * 删除用户
 *
 * @param ids
 */
export function deleteUsers(ids: string) {
  return request({
    url: '/user/delete/' + ids,
    method: 'delete',
  });
}
